The Client is the centerpiece of the Box SDK. We provide several subclasses of the Client that can be especially useful during development of applications using the SDK.

  • The LoggingClient sets up logging to stdout to help visualize API calls made by the SDK.
  • The DeveloperTokenClient sets up auth using a developer token that you can get from the Box Developer Console.
  • The DevelopmentClient does both!

In [1]:
from boxsdk import DevelopmentClient
client = DevelopmentClient()


Enter developer token: ERTP2iXmvV6cPMAAkLfwufBiy3k0VbUb

In [2]:
client.user('me').get()


GET https://api.box.com/2.0/users/me {'headers': {'Authorization': 'Bearer ERTP2iXmvV6cPMAAkLfwufBiy3k0VbUb',
             'User-Agent': 'box-python-sdk-2.0.0a12'},
 'params': None}
"GET https://api.box.com/2.0/users/me" 200 427
{'Strict-Transport-Security': 'max-age=31536000', 'Cache-Control': 'no-cache, no-store', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'BOX-REQUEST-ID': '05vmol15bp0htusbqk406r8e335', 'Date': 'Mon, 04 Jun 2018 23:44:03 GMT', 'Content-Type': 'application/json', 'Age': '0', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive'}
{'address': '',
 'avatar_url': 'https://cloud.app.box.com/api/avatar/large/202476009',
 'created_at': '2013-09-09T14:35:35-07:00',
 'id': '202476009',
 'job_title': '',
 'language': 'en',
 'login': 'jmeadows@box.com',
 'max_upload_size': 34359738368,
 'modified_at': '2018-06-04T10:26:57-07:00',
 'name': 'Jeffrey Meadows',
 'phone': '',
 'space_amount': 1000000000000000.0,
 'space_used': 131650134148,
 'status': 'active',
 'timezone': 'America/Los_Angeles',
 'type': 'user'}

Out[2]:
<Box User - me (Jeffrey Meadows)>

In [5]:
from boxsdk.exception import BoxAPIException
try:
    client.file('1234').get()
except BoxAPIException as e:
    pass


GET https://api.box.com/2.0/files/1234 {'headers': {'Authorization': 'Bearer ERTP2iXmvV6cPMAAkLfwufBiy3k0VbUb',
             'User-Agent': 'box-python-sdk-2.0.0a12'},
 'params': None}
"GET https://api.box.com/2.0/files/1234" 404 304
{'Strict-Transport-Security': 'max-age=31536000', 'Cache-Control': 'no-cache, no-store', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding', 'BOX-REQUEST-ID': '0bc0o82ru5o7hegpivej1dcsmbf', 'Date': 'Mon, 04 Jun 2018 23:45:37 GMT', 'Content-Type': 'application/json', 'Age': '0', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive'}
{'code': 'not_found',
 'context_info': {'errors': [{'message': "Invalid value 'f_1234'. 'item' with "
                                         "value 'f_1234' not found",
                              'name': 'item',
                              'reason': 'invalid_parameter'}]},
 'help_url': 'http://developers.box.com/docs/#errors',
 'message': 'Not Found',
 'request_id': 'r5fkoyfrzypwe2pe',
 'status': 404,
 'type': 'error'}

As you can see, requests are logged in blue; successful responses in green, error responses in red.


In [ ]: